package pokergame;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Game {
    /**
     * 买牌
     * @return
     */
    public List<Poker> buyPokers() {
        List<Poker> pokers = new ArrayList<>();
        String[] suits = {"♥" , "♠" , "♦" , "♣" };
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                Poker poker = new Poker(suits[i],j+1);
                pokers.add(poker);
            }
        }
        return pokers;
    }

    /**
     * 洗牌
     * @param pokers
     */
    public void  shuffle(List<Poker> pokers) {
        for (int i = pokers.size() - 1; i > 0 ; i--) {
            Random rand = new Random();
            int ret = rand.nextInt(i);
            sway(pokers,i,ret);
        }

    }

    /**
     * 功能：交换函数
     * @param pokers
     * @param i
     * @param j
     */
    private void sway(List<Poker> pokers,int i,int j) {
        Poker tmp = pokers.get(i);
        pokers.set(i,pokers.get(j));
        pokers.set(j,tmp);
    }

    public void deal(List<Poker> pokers, List<Player> player) {
        List<List<Poker>> hand = new ArrayList<>();
        List<Poker> hand1 = new ArrayList<>();
        List<Poker> hand2 = new ArrayList<>();
        List<Poker> hand3 = new ArrayList<>();
        hand.add(hand1);
        hand.add(hand2);
        hand.add(hand3);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                hand.get(j).add(pokers.get(0));
                pokers.remove(0);
            }
        }
        player.get(0).setPokers(hand1);
        player.get(1).setPokers(hand2);
        player.get(2).setPokers(hand3);

    }
}
